﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
//using System.Xml.Linq;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.DAL;
using Telerik.Web.UI;

namespace KPIS.GERP.GHRMS.APP.App_UI.Forms
{
    public partial class TR_CompetencyTypes : System.Web.UI.Page
    {
        private SsMng ssMng = new SsMng();
        TR_CompetencyTypesInfo tr_competencyinfo = new TR_CompetencyTypesInfo();
        TR_CompetencyTypesDAL tr_competencydal = new TR_CompetencyTypesDAL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //Session["tmp_emp_seq"] = ssMng.EmpSeqI;
                grdTRCompetencyTypes.DataSource = tr_competencydal.GetFill();
                grdTRCompetencyTypes.DataBind();
            }
        }

        protected void grdTRCompetencyTypes_ItemCommand(object o, GridCommandEventArgs e)
        {
           if (e.CommandName == "Sort" || e.CommandName == "Filter")
            {
                grdTRCompetencyTypes.DataSource = tr_competencydal.GetFill();
                grdTRCompetencyTypes.DataBind();
            }
           if (e.CommandName == "DataEdit")
           {
               UpdateUI("Update");
           }

        }
         
        protected void grdTRCompetencyTypes_ItemDataBound(object o, GridItemEventArgs e)
        {
          
        }
        protected void cmdAddCompetencyTypes_Click(object sender, EventArgs e)
        {
            UpdateUI("AddNew"); 
           
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strCompetencyTypeSeq = txtCompetencyTypeSeq.Text; 
            string strCompetencyTypeDescr = txtCompetencyTypeDescr.Text;
            int UserID = ssMng.EmpSeqI;
            DateTime dtNow = DateTime.Now;

            tr_competencyinfo.competency_type_seq = Convert.ToInt32(strCompetencyTypeSeq);
            tr_competencyinfo.competency_type_descr = strCompetencyTypeDescr;
            //tr_competencyinfo.updated_by = main.ConvertNullInt(strUserID);
            //tr_competencyinfo.updated_when = main.ConvertNullDateTime(dtNow);            
        }
        protected void btnCancel_Click(object sender, EventArgs e)
        {
            ClearControl();
            UpdateUI("Cancel");
        }
        protected void UpdateUI(string strCommand)
        {
            switch (strCommand)
            {
                case "AddNew":
                    tblTRCompetencyTypes.Visible = false;
                    CompetencyTypesEdit.Visible = true;
                    txtCompetencyTypeSeq.Enabled = false;

                    break;

                case "Save":
                    tblTRCompetencyTypes.Visible = false;
                    CompetencyTypesEdit.Visible = true;

                    break;

                case "Cancel":
                    tblTRCompetencyTypes.Visible = true;
                    CompetencyTypesEdit.Visible = false;

                    break;

                case "Update":
                    tblTRCompetencyTypes.Visible = false;
                    CompetencyTypesEdit.Visible = true;
                    txtCompetencyTypeSeq.Enabled = false;

                    break;

 
            }
        }
        //============================ control events ==============================
        protected void ClearControl()
        {
            txtCompetencyTypeSeq.Text = "";
            txtCompetencyTypeDescr.Text = "";            
        }
        
    }
   
}

